package m202406.d06;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/6 21:57
 */
public class OD_T1 {

    public static void main(String[] args) {
//        Integer[] a = new Integer[]{4, 1, 3};
//        Arrays.sort(a, (i1, i2) -> i1 - i2);
        Map<Character, Integer> map = new HashMap<>();
        map.put('$', 0);
        map.put('&', 1);
        map.put('*', 2);
        int c = 3;
        for (char i = '0'; i <= '9'; i++) {
            map.put(i, c);
            c++;
        }
        for (char i = 'A'; i <= 'Z'; i++) {
            map.put(i, c);
            c++;
        }

        Scanner scanner = new Scanner(System.in);
        List<String[]> list = new ArrayList<>(Arrays.stream(scanner.nextLine().split(","))
                .map(x -> new String[]{x.substring(0, 2), x.substring(2)})
                .toList());

        list.sort((sa1, sa2) -> {
            int f1 = map.get(sa1[0].charAt(0)) - map.get(sa2[0].charAt(0));
            if (f1 != 0) {
                return f1;
            }
            int f2 = map.get(sa1[0].charAt(1)) - map.get(sa2[0].charAt(1));
            if (f2 != 0) {
                return f2;
            }
            return Integer.parseInt(sa1[1]) - Integer.parseInt(sa2[1]);
        });

        String rs = list.stream().map(x -> x[0] + x[1]).collect(Collectors.joining(","));
        System.out.println(rs);
    }
}
